/*     */ package com.newcrm.util;
/*     */ 
/*     */ import java.io.PrintStream;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Date;
/*     */ import net.sf.json.JSONArray;
/*     */ import net.sf.json.JSONException;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.http.HttpResponse;
/*     */ import org.apache.http.client.HttpClient;
/*     */ import org.apache.http.client.methods.HttpPost;
/*     */ import org.apache.http.entity.StringEntity;
/*     */ import org.apache.http.impl.client.HttpClientBuilder;
/*     */ import org.apache.http.util.EntityUtils;
/*     */ 
/*     */ public class OpenAPIManager
/*     */ {
/*     */   public static String getCreateOpenAPIResult()
/*     */   {
/*  35 */     String date = date2Str4(new Date());
/*     */ 
/*  37 */     String token = "be1polyv2188";
/*  38 */     String sign = MD5.getMD5(token + date);
/*     */ 
/*  41 */     String url = "http://127.0.0.1:8080/newCRM/openAPI/customer/new?sign=" + 
/*  42 */       sign + "&timestamp=" + date;
/*     */ 
/*  44 */     HttpClient httpClient = HttpClientBuilder.create().build();
/*  45 */     System.out.println(url);
/*     */     try
/*     */     {
/*  49 */       HttpPost request = new HttpPost(url);
/*  50 */       request.addHeader("content-type", "application/json");
/*     */ 
/*  79 */       StringEntity params = new StringEntity("{\"companyName\":\"李楠30228\",\"categoryId\":\"1类客户\",\"companyNote\":\"注册用户\",\"operationUserId\":\"admin\",\"visible\":\"公共数据\",\"permissionId\":\"销售部\",\"companyExtInfos\": [{\"key\":\"phone\", \"value\":\"13677771111\"},{\"key\":\"email\", \"value\":\"9125111111@qq.com\"},{\"key\":\"im\", \"value\":\"9125511111\"},{\"key\":\"website\", \"value\":\"www.qidian11.com\"}, ],}", 
/*  89 */         "UTF-8");
/*     */ 
/*  91 */       request.setEntity(params);
/*  92 */       HttpResponse response = httpClient.execute(request);
/*  93 */       String body = EntityUtils.toString(response.getEntity(), "UTF-8");
/*  94 */       System.out.println("body:" + body);
/*     */ 
/*  96 */       JSONObject json = JSONObject.fromObject(body);
/*  97 */       if ("0".equals(getJSONStringValue(json, "error"))) {
/*  98 */         System.out.println("调用结果：" + 
/*  99 */           getJSONStringValue(json, "message"));
/* 100 */         System.out.println("创建客户ID：" + 
/* 101 */           getJSONStringValue(json, "customerId"));
/* 102 */       } else if ("2".equals(getJSONStringValue(json, "error"))) {
/* 103 */         System.out.println("调用结果：" + 
/* 104 */           getJSONStringValue(json, "message"));
/* 105 */         System.out.println("重复客户ID：" + 
/* 106 */           getJSONStringValue(json, "customerId"));
/* 107 */       } else if ("1".equals(getJSONStringValue(json, "error"))) {
/* 108 */         System.out.println("调用失败信息： " + 
/* 109 */           getJSONStringValue(json, "message"));
/*     */       }
/*     */ 
/*     */     }
/*     */     catch (Exception localException)
/*     */     {
/*     */     }
/*     */ 
/* 122 */     return null;
/*     */   }
/*     */ 
/*     */   public static String getQueryOpenAPIResult()
/*     */   {
/* 135 */     String date = date2Str4(new Date());
/*     */ 
/* 137 */     String token = "be1polyv2188";
/* 138 */     String sign = MD5.getMD5(token + date);
/*     */ 
/* 141 */     String url = "http://127.0.0.1:8080/newCRM/openAPI/customer/query?sign=" + 
/* 142 */       sign + "&timestamp=" + date;
/*     */ 
/* 144 */     HttpClient httpClient = HttpClientBuilder.create().build();
/* 145 */     System.out.println(url);
/*     */     try
/*     */     {
/* 149 */       HttpPost request = new HttpPost(url);
/* 150 */       request.addHeader("content-type", "application/json");
/*     */ 
/* 152 */       StringEntity params = new StringEntity("{\"phone\":\"136111100001\",\"im\":\"9125500921\",}", 
/* 158 */         "UTF-8");
/*     */ 
/* 160 */       request.setEntity(params);
/* 161 */       HttpResponse response = httpClient.execute(request);
/* 162 */       String body = EntityUtils.toString(response.getEntity(), "UTF-8");
/* 163 */       System.out.println("body:" + body);
/*     */ 
/* 165 */       JSONObject json = JSONObject.fromObject(body);
/* 166 */       if (json.has("result")) {
/* 167 */         JSONArray result = json.getJSONArray("result");
/* 168 */         for (int i = 0; i < result.size(); i++) {
/* 169 */           JSONObject item = result.getJSONObject(i);
/* 170 */           System.out.println("Name：" + item.get("Name"));
/* 171 */           System.out.println("website：" + item.get("website"));
/* 172 */           System.out.println("im：" + item.get("im"));
/* 173 */           System.out.println("phone：" + item.get("phone"));
/* 174 */           System.out.println("email：" + item.get("email"));
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/*     */     }
/*     */     catch (Exception localException)
/*     */     {
/*     */     }
/*     */ 
/* 189 */     return null;
/*     */   }
/*     */ 
/*     */   public static String date2Str4(Date date)
/*     */   {
/* 199 */     if (date == null) {
/* 200 */       return "";
/*     */     }
/* 202 */     SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
/* 203 */       "yyyyMMddHHmmss");
/* 204 */     return simpleDateFormat.format(date);
/*     */   }
/*     */ 
/*     */   public static String getJSONStringValue(JSONObject json, String key)
/*     */   {
/* 215 */     if (json == null) {
/* 216 */       return null;
/*     */     }
/* 218 */     if ((key == null) || (key.trim().length() == 0)) {
/* 219 */       return null;
/*     */     }
/*     */ 
/* 222 */     if (!json.has(key))
/* 223 */       return null;
/*     */     try
/*     */     {
/* 226 */       return json.getString(key); } catch (JSONException e) {
/*     */     }
/* 228 */     return null;
/*     */   }
/*     */ 
/*     */   public static void main(String[] args)
/*     */     throws Exception
/*     */   {
/* 241 */     String result = getQueryOpenAPIResult();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.util.OpenAPIManager
 * JD-Core Version:    0.6.1
 */